﻿using EFCORE仓储模式.Contracts;
using EFCORE仓储模式.Data;
using EFCORE仓储模式.Data.Repositories;
using Microsoft.EntityFrameworkCore;

namespace EFCORE仓储模式.Extensions
{
    //服务扩展类
    public static class ServiceExtensions
    {
        //跨域配置
        public static void ConfigureCors(this IServiceCollection services)
        {
            services.AddCors(options =>
            {
                //options.AddPolicy("AnyPolicy",
                //    builder => builder.AllowAnyOrigin()
                //        .AllowAnyMethod()
                //        .AllowAnyHeader());

                options.AddDefaultPolicy(builder => builder.AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());
            });
        }

        public static void ConfigureSqlServerContext(this IServiceCollection services, IConfiguration config)
        {
            var connectionString = config.GetConnectionString("GameDb");
            services.AddDbContext<DataMangermentDbContext>(
                builder => builder.UseSqlServer(connectionString));
        }

        public static void ConfigureRepositoryWrapper(this IServiceCollection services)
        {
            services.AddScoped<IRepositoryWrapper, RepositoryWrapper>();
        }
    }
}